﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;
using System.Drawing.Drawing2D;
using System.Media;

namespace TankWin.Classes
{
    class GUIMainMenu:GUI
    {
        public static SoundPlayer _move_player;
        public static SoundPlayer _enter_player;
        //////////////////////////////////////
        public const int _Number = 6;
        protected int _curItem = 0;//chi so item duoc chon
        static string[] _menuItem = new string[_Number]
        {
            "PLAY",
            "OPTION",
            "CONSTRUCTION",
            "HIGH SCORE",
            "ABOUT",
            "EXIT"
        };
        public GUIMainMenu()
        {
            try
            {
                _move_player = new SoundPlayer();
                _enter_player = new SoundPlayer();
                _move_player.Stream = global::TankWin.ImageTank.fire;
                _enter_player.SoundLocation = @"C:\Windows\Media\Speech Off.wav";

                _move_player.Load();
                _enter_player.Load();

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        ////////////////////////////////////
        //ve len man hinh
        //////////////////////////////////////
        public override void Draw(Graphics _G)
        {
            Image im = global::TankWin.ImageTank.background;
            Bitmap _buffer = new Bitmap((int)_G.VisibleClipBounds.Width, (int)_G.VisibleClipBounds.Height);
            Graphics _gbuffer = Graphics.FromImage(_buffer);
            _gbuffer.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            _gbuffer.Clear(Color.White);

            _gbuffer.DrawImageUnscaled(im, 0, 0);
            Font f1 = new Font("Times New Roman", 14, FontStyle.Bold);
            Font f2 = new Font("Times New Roman", 13, FontStyle.Bold);
            for (int i = 0; i < _Number; i++)
            {
                string _item = _menuItem[i];
               
                _gbuffer.DrawString(_item, f1, Brushes.Black, new PointF((320-13*_item.Length/2), 190 + 68 * i));
                _gbuffer.DrawString(_item, f2, Brushes.White, new PointF((320-13*_item.Length/2), 190 + 68 * i));
               

                if (i == _curItem)
                {
                    _gbuffer.DrawString(_item, f2, Brushes.DarkBlue, new PointF((320-14*_item.Length/2) , 190 + 68 * i));
                }
            }
            _G.DrawImageUnscaled(_buffer, 0, 0);
        }
        //////////////////////////////////////////////////////////////////////////
        long _start = 0;
        long _end;

        public override void InputKey(Keys _key)
        {
            if (_move_player.IsLoadCompleted && GUIPlay._hasSound)
            {
                _end = System.DateTime.Now.Ticks / 10000;
                if (_end - _start >= 150)
                {
                    _start = _end;
                    _move_player.Play();
                }
            }
            if (GUIPlay._isAsking == true)
            {
                GUIPlay._isAsking = false;
                return;
            }
            switch (_key)
            {
                case Keys.Up:
                    _curItem += _Number - 1;
                    _curItem %= _Number;
                    break;
                case Keys.Down:
                    _curItem++;
                    _curItem %= _Number;
                    break;
                case Keys.Left:
                    _curItem++;
                    _curItem%=_Number;
                    break;
                case Keys.Right:
                    _curItem+=_Number-1;
                    _curItem%=_Number;
                    break;
                case Keys.Enter:
                    if(_enter_player.IsLoadCompleted&&GUIPlay._hasSound)
                        _enter_player.Play();
                    frMain._statusGUI=(EStatusGUI)_curItem;
                    break;
            }
        }

    }
}
